<?php

namespace app\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Validate;

class Contact extends BaseController {
public function create() {
$data = request()->post();
// 数据验证
$validate = Validate::rule([
'name'  => 'require|max:50',
'email' => 'require|email',
'message' => 'require|min:10'
]);
if (!$validate->check($data)) {
return json(['code' => 400, 'msg' => $validate->getError()]);
}
// 写入数据库
Db::table('contact')->insert($data);
return json(['code' => 200, 'msg' => '提交成功']);
}
}